package trading.ctm.yunjing.module.information.fragment

import android.content.Intent
import android.os.Bundle
import android.support.v4.content.LocalBroadcastManager
import android.view.View
import cc.vv.baselibrary.fragment.BaseFragment
import cc.vv.baselibrary.view.BaseTopBarView
import cc.vv.lkbasecomponent.util.LKSPUtil
import kotlinx.android.synthetic.main.fragment_information.*
import trading.ctm.yunjing.R
import trading.ctm.yunjing.module.information.adapter.InformationViewPageAdapter

/**
 * 资讯
 */
class InformationFragment : BaseFragment(){

    override fun initLayoutRes(): Int {
        return R.layout.fragment_information
    }

    override fun initView(bundle: Bundle?) {
        super.initView(bundle)
        }

    override fun onResume() {
        super.onResume()
        val i = LKSPUtil.getInstance().getInt("isTableHost", 1)
        if(i == 0){
            btbv_if_information_title.iv_ljtb_left_back.visibility = View.VISIBLE
            LKSPUtil.getInstance().put("isTableHost", 1)
        }else{
            btbv_if_information_title.iv_ljtb_left_back.visibility = View.GONE
        }
    }

    override fun initData(bundle: Bundle?) {
        super.initData(bundle)
        val titles = arrayListOf("推荐","市场快讯","地产快讯","品种快讯","资产快讯","拍卖快讯","最新快讯")
        var fragments = ArrayList<InformationViewpagerFragment>()
        for (i in 0 until titles.size){
            val fragment =InformationViewpagerFragment()
            fragments.add(fragment)
        }
        vp_fi_content.adapter = InformationViewPageAdapter(fragmentManager, fragments, titles)
        tab_if_tablayout.setupWithViewPager(vp_fi_content)

    }

    override fun initAction(bundle: Bundle?) {
        super.initAction(bundle)

        btbv_if_information_title.setEventInterface(object : BaseTopBarView.EventInterface {
            override fun leftOnClick() {
                val intent = Intent("fragment")
                intent.putExtra("fragment_key", 0)
                LocalBroadcastManager.getInstance(context).sendBroadcast(intent)
            }

            override fun leftCloseClick() {
            }

            override fun rightOnClick() {
            }

        })


    }

}